package com.avoid.easymqtt.broker;

import com.avoid.easymqtt.common.MixAll;
import com.avoid.easymqtt.remoting.common.RemotingHelper;
import com.avoid.easymqtt.remoting.common.RemotingUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 描述
 *
 * @author avoid@fiture.com
 * @date 2022/5/9
 * @motto Life is so short,do something to make yourself happy,such as coding
 */
public class BrokerConfig {
    private static final Logger log = LoggerFactory.getLogger(RemotingHelper.EASYMQTT_REMOTING);

    private String namesrvAddr = System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, System.getenv(MixAll.NAMESRV_ADDR_ENV));
    private final String brokerIP = RemotingUtil.getLocalAddress();
    private final String brokerName = localHostName();

    private int connectThreadPoolQueueCapacity = 1000;
    private int connectMessageThreadPoolNums = Runtime.getRuntime().availableProcessors() * 2;

    public static String localHostName() {
        try {
            return InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            log.error("Failed to obtain the host name", e);
        }

        return "DEFAULT_BROKER";
    }

    public String getNamesrvAddr() {
        return namesrvAddr;
    }

    public void setNamesrvAddr(String namesrvAddr) {
        this.namesrvAddr = namesrvAddr;
    }

    public String getBrokerIP() {
        return brokerIP;
    }

    public String getBrokerName() {
        return brokerName;
    }

    public int getConnectThreadPoolQueueCapacity() {
        return connectThreadPoolQueueCapacity;
    }

    public void setConnectThreadPoolQueueCapacity(int connectThreadPoolQueueCapacity) {
        this.connectThreadPoolQueueCapacity = connectThreadPoolQueueCapacity;
    }

    public int getConnectMessageThreadPoolNums() {
        return connectMessageThreadPoolNums;
    }

    public void setConnectMessageThreadPoolNums(int connectMessageThreadPoolNums) {
        this.connectMessageThreadPoolNums = connectMessageThreadPoolNums;
    }
}
